package com.force.jianghuling.activity;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.avos.avoscloud.AVAnalytics;
import com.force.jianghuling.R;
import com.force.jianghuling.base.BaseActivity;
import com.litesuits.common.assist.Toastor;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

/**
 * 使用xUtils引用布局
 */
@ContentView(R.layout.activity_splash)
public class SplashActivity extends BaseActivity {

    @ViewInject(R.id.iv_splash_background)
    private ImageView mIvBackGround;

    @ViewInject(R.id.iv_splash_text)
    private ImageView mIvText;

    private Toastor mToastor;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mToastor = new Toastor(SplashActivity.this);
        initData();
        AVAnalytics.trackAppOpened(getIntent());
    }

    private void initData() {
        //给相应组件绑定相应的动画
        Animator animator = AnimatorInflater.loadAnimator(SplashActivity.this, R.animator.fadein3f_3s);
        Animator animator1 = AnimatorInflater.loadAnimator(SplashActivity.this, R.animator.fadein3s);
        animator.setTarget(mIvBackGround);
        animator1.setTarget(mIvText);
        //利用组合动画来实现效果
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(animator1).after(animator);
        animatorSet.start();
        //对动画结束进行监听
        animator1.addListener(new AnimatorListenerAdapter() {
            //动画结束监听
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mToastor.showToast(R.string.toast_animate_over);
                startActivity(new Intent(context,LoginActivity.class));
                finish();
            }
            //动画开始监听
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                mIvText.setVisibility(View.VISIBLE);
            }
        });

    }
}








































